package com.example.demo.singletonpattern;

/**
 * @author :xie
 * Email: 1487471733@qq.com
 * Date: 2018/9/7
 * Time: 11:03
 * Describe:  饿汉式
 */
public class SingleObject {


    private String canShu;

    /**
     * 创建 SingleObject 的一个对象
     */
    private static SingleObject instance = new SingleObject();

    /**
     * 让构造函数为 private，这样该类就不会被实例化
     */
    private SingleObject(){}

    /**
     * 获取唯一可用的对象
     * @return 实例
     */
    public static SingleObject getInstance(){
        return instance;
    }


    public String getCanShu() {
        return canShu;
    }

    public void setCanShu(String canShu) {
        this.canShu = canShu;
    }

    public void showMessage(){
        System.out.println("Hello World!"+this.canShu);
    }
}
